#! /bin/sh
. "${srcdir=.}/init.sh"; path_prepend_ . ../src

# Test ObjectiveC extractor.

cat <<\EOF > xg-ob-1.m
id str = _(@
"conca" /* comment */
@
// another comment
 "tenated");

_(@"foo") _ ( @"foo2" /* test */ )

"_()"

"  \" _(foo) \" /* comment "

_ // test
(@ /* comment " */ "test"
@
" test2"
)

NSLocalizedString(@"Information", @"")

// This is a C format string.
printf (gettext ("foo %s"));

// This is an Objective-C format string without Objective-C extensions.
// Therefore it's OK to label it as a C format string.
stringWithFormat (gettext ("bar %s"));

// It is unknown whether this is used as a C format string or as an Objective-C
// format string. But in any case, it does not have Objective-C extensions.
// Therefore it's OK to label it as a C format string.
gettext ("baz %s");

// This is an Objective-C format string with Objective-C extensions.
stringWithFormat (gettext ("objcbar %@"));

// This is a format string with Objective-C extensions. It cannot be used as a
// C format string. Therefore it is better to label it as an Objective-C format
// string.
gettext ("objcbaz %@");
EOF

: ${XGETTEXT=xgettext}
${XGETTEXT} --omit-header -k_ -kNSLocalizedString -d xg-ob-1.tmp xg-ob-1.m || Exit 1
LC_ALL=C tr -d '\r' < xg-ob-1.tmp.po > xg-ob-1.po || Exit 1

cat <<\EOF > xg-ob-1.ok
#: xg-ob-1.m:2
msgid "concatenated"
msgstr ""

#: xg-ob-1.m:7
msgid "foo"
msgstr ""

#: xg-ob-1.m:7
msgid "foo2"
msgstr ""

#: xg-ob-1.m:14
msgid "test test2"
msgstr ""

#: xg-ob-1.m:19
msgid "Information"
msgstr ""

#: xg-ob-1.m:22
#, c-format
msgid "foo %s"
msgstr ""

#: xg-ob-1.m:26
#, c-format
msgid "bar %s"
msgstr ""

#: xg-ob-1.m:31
#, c-format
msgid "baz %s"
msgstr ""

#: xg-ob-1.m:34
#, objc-format
msgid "objcbar %@"
msgstr ""

#: xg-ob-1.m:39
#, objc-format
msgid "objcbaz %@"
msgstr ""
EOF

: ${DIFF=diff}
${DIFF} xg-ob-1.ok xg-ob-1.po
result=$?

exit $result
